Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentations to some more builtin files #1505

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tonyfettes
Copy link
Contributor

This PR add documentations to publich APIs in @Builtin package, completing upto files starts with b.

Copy link

peter-jerry-ye-code-review bot commented Jan 18, 2025

‼️ This code review is generated by a bot. Please verify the content before trusting it.

I've reviewed the git diff and here are the top 3 potential issues I've identified:

  1. In BigInt::op_div function (builtin/bigint_nonjs.mbt), there's a commented out guard for division by zero:
// TODO: 
// guard (other != zero, "division by zero")  

This could lead to undefined behavior if not properly handled. The guard should be implemented to prevent division by zero.

  1. In BytesView::to_uint_be and similar functions (builtin/bytesview.mbt), there's no explicit length check before accessing the bytes. While there are bounds checks in the underlying op_get, it would be more efficient and safer to check the length once at the beginning:
pub fn BytesView::to_uint_be(self : BytesView) -> UInt {
  // Missing length check: guard self.len >= 4 else { abort("insufficient bytes") }
  (self[0].to_uint() << 24) +
  (self[1].to_uint() << 16) +
  (self[2].to_uint() << 8) +
  self[3].to_uint()
}
  1. In BigInt::from_string (builtin/bigint_nonjs.mbt), there's potential for overflow in the digit parsing loop. While the function does check for empty strings, it doesn't validate that each character is actually a valid decimal digit before converting it:
// Could add explicit digit validation:
// guard c >= '0' && c <= '9' else { abort("invalid digit in decimal string") }

These issues could affect the reliability and safety of the code, particularly when handling edge cases or invalid input.

@coveralls
Copy link
Collaborator

coveralls commented Jan 18, 2025

Pull Request Test Coverage Report for Build 4827

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage remained the same at 83.072%

Files with Coverage Reduction New Missed Lines %
builtin/byte.mbt 1 91.43%
Totals Coverage Status
Change from base Build 4826: 0.0%
Covered Lines: 4878
Relevant Lines: 5872

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants